package demo;

import api.GreetingService;
import api.GreetingServiceAsync;
import org.apache.dubbo.config.ApplicationConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.ServiceConfig;

import java.io.IOException;

/**
 * Copyright (c)  by www.leya920.com
 * All right reserved.
 * Create Date: 2020-11-21 17:04
 * Create Author: xuweiwei
 * File Name: ApiProviderAsync.java
 * Last version:  1.0
 * Function: //TODO
 * Last Update Date: 2020-11-21 17:04
 * Last Update Log:
 * Comment: //TODO
 **/
public class ApiProviderAsync {


    public static void main(String[] args) throws IOException {
        // 创建ServiceConfig实例
        ServiceConfig<GreetingServiceAsync> serviceConfig = new ServiceConfig<>();

        // 设置应用程序配置
        serviceConfig.setApplication(new ApplicationConfig("first-dubbo-provider"));


        // 设置服务注册中心信息
        RegistryConfig registryConfig = new RegistryConfig("zookeeper://127.0.0.1:2181");
        serviceConfig.setRegistry(registryConfig);

        // 设置接口与实现类
        serviceConfig.setInterface(GreetingServiceAsync.class);
        serviceConfig.setRef(new GreetingServiceAsyncImpl()); // 实现类

        // 设置服务分组与版本
        serviceConfig.setVersion("1.0.0");
        serviceConfig.setGroup("dubbo");

        // 设置线程池策略
//        HashMap<String,String> paramters = new HashMap<>();
//        paramters.put("threadpool","mythreadpool");
//        serviceConfig.setParameters(paramters);

        // 导出服务
        serviceConfig.export();

        // 挂起线程 避免服务停止
        System.out.println("service is started");
        System.in.read();
    }
}
